package com.iot.hmi.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * Note: Length of timestamp is 13.
 */
public class TimeHelper {

    private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String stamp2datetime(Long timestamp) {
        return new SimpleDateFormat(DATE_TIME_FORMAT).format(new Date(timestamp));
    }

    public static Long datetime2stamp(String dateTime) throws ParseException {
        return new SimpleDateFormat(DATE_TIME_FORMAT).parse(dateTime).getTime();
    }

    public static Long todayStartStamp() {
        return LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toEpochSecond() * 1000;
    }

}
